import { hasOwn, isReserved, bind, noop } from '../shared/utils.js'

function initMethods (vm, methods) {
  const data = vm.$options.data
  for (const key in methods) {
    if (methods[key] == null) {
      console.warn(`未找到"${key}"`)
      return
    }
    if (data && hasOwn(data, key)) {
      console.warn(`"${key}"已经存在`)
      return
    }
    if ((key in vm) && isReserved(key)) {
      console.warn(`"${key}"重复`)
      return
    }
    vm[key] = methods[key] == null ? noop : bind(methods[key], vm)
  }
}

export default initMethods
